package com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.bean;

import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.AddCategoryDTO;
import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.EditCategoryDTO;
import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.GetCategoryDTO;
import com.example.mybatis.sqlserver.springbootmybatissqlserver.pojo.dto.GetCategoryTreeDTO;

import java.util.Date;

public class CategoryBean {
    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.id
     *
     * @mbggenerated
     */
    private String id;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.fk_category_parent
     *
     * @mbggenerated
     */
    private String fkCategoryParent;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.name
     *
     * @mbggenerated
     */
    private String name;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.only_code
     *
     * @mbggenerated
     */
    private String onlyCode;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.level
     *
     * @mbggenerated
     */
    private Integer level;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.sort_index
     *
     * @mbggenerated
     */
    private String sortIndex;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.is_show
     *
     * @mbggenerated
     */
    private Boolean isShow;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.add_time
     *
     * @mbggenerated
     */
    private Date addTime;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.is_delete
     *
     * @mbggenerated
     */
    private Boolean isDelete;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.lastest_version
     *
     * @mbggenerated
     */
    private Long lastestVersion;

    /**
     * This field was generated by MyBatis Generator.
     * This field corresponds to the database column tb_category.Last_sync_time
     *
     * @mbggenerated
     */
    private Date lastSyncTime;

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_category
     *
     * @mbggenerated
     */
    public CategoryBean(String id, String fkCategoryParent, String name, String onlyCode, Integer level, String sortIndex, Boolean isShow, Date addTime, Boolean isDelete, Long lastestVersion, Date lastSyncTime) {
        this.id = id;
        this.fkCategoryParent = fkCategoryParent;
        this.name = name;
        this.onlyCode = onlyCode;
        this.level = level;
        this.sortIndex = sortIndex;
        this.isShow = isShow;
        this.addTime = addTime;
        this.isDelete = isDelete;
        this.lastestVersion = lastestVersion;
        this.lastSyncTime = lastSyncTime;
    }

    public CategoryBean(){}

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.id
     *
     * @return the value of tb_category.id
     *
     * @mbggenerated
     */
    public String getId() {
        return id;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.fk_category_parent
     *
     * @return the value of tb_category.fk_category_parent
     *
     * @mbggenerated
     */
    public String getFkCategoryParent() {
        return fkCategoryParent;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.name
     *
     * @return the value of tb_category.name
     *
     * @mbggenerated
     */
    public String getName() {
        return name;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.only_code
     *
     * @return the value of tb_category.only_code
     *
     * @mbggenerated
     */
    public String getOnlyCode() {
        return onlyCode;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.level
     *
     * @return the value of tb_category.level
     *
     * @mbggenerated
     */
    public Integer getLevel() {
        return level;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.sort_index
     *
     * @return the value of tb_category.sort_index
     *
     * @mbggenerated
     */
    public String getSortIndex() {
        return sortIndex;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.is_show
     *
     * @return the value of tb_category.is_show
     *
     * @mbggenerated
     */
    public Boolean getIsShow() {
        return isShow;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.add_time
     *
     * @return the value of tb_category.add_time
     *
     * @mbggenerated
     */
    public Date getAddTime() {
        return addTime;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.is_delete
     *
     * @return the value of tb_category.is_delete
     *
     * @mbggenerated
     */
    public Boolean getIsDelete() {
        return isDelete;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.lastest_version
     *
     * @return the value of tb_category.lastest_version
     *
     * @mbggenerated
     */
    public Long getLastestVersion() {
        return lastestVersion;
    }

    /**
     * This method was generated by MyBatis Generator.
     * This method returns the value of the database column tb_category.Last_sync_time
     *
     * @return the value of tb_category.Last_sync_time
     *
     * @mbggenerated
     */
    public Date getLastSyncTime() {
        return lastSyncTime;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public static CategoryBean from(AddCategoryDTO dto){
        CategoryBean bean = new CategoryBean();
        bean.addTime = new Date();
        bean.lastSyncTime = bean.addTime;
        bean.isDelete = false;
        bean.isShow = true;
        bean.lastestVersion = 0L ;
        bean.name = dto.categoryName;
        bean.fkCategoryParent = dto.parentCategoryId;
        bean.sortIndex = dto.sortIndex;
        bean.onlyCode = dto.onlyCode;
        return bean;
    }

    public static CategoryBean from(EditCategoryDTO dto) {
        CategoryBean bean = new CategoryBean();
        bean.id = dto.categoryId;
        bean.lastSyncTime = new Date();
        bean.isShow = dto.isShow;
        bean.name = dto.categoryName;
        bean.sortIndex = dto.sortIndex;
        bean.onlyCode = dto.onlyCode;
        return bean;
    }

    public static GetCategoryDTO toGetCategoryDTO(CategoryBean categoryBean) {
        GetCategoryDTO dto = new GetCategoryDTO();
        dto.categoryName = categoryBean.name;
        dto.level = categoryBean.level;
        dto.categoryId = categoryBean.id;
        return dto;
    }

    public static GetCategoryTreeDTO GetCategoryTreeDTO(CategoryBean categoryBean) {
        GetCategoryTreeDTO dto = new GetCategoryTreeDTO();
        dto.layer = categoryBean.level;
        dto.categoryId = categoryBean.id;
        // TODO: 2019/2/21 此字段值未知?
//        dto.checked
        dto.code = categoryBean.onlyCode;
        dto.text = categoryBean.name;
        dto.delete = categoryBean.isDelete;
        dto.parentId = categoryBean.fkCategoryParent;
        return dto;
    }

    @Override
    public String toString() {
        return "CategoryBean{" +
                "id='" + id + '\'' +
                ", fkCategoryParent='" + fkCategoryParent + '\'' +
                ", name='" + name + '\'' +
                ", onlyCode='" + onlyCode + '\'' +
                ", level=" + level +
                ", sortIndex='" + sortIndex + '\'' +
                ", isShow=" + isShow +
                ", addTime=" + addTime +
                ", isDelete=" + isDelete +
                ", lastestVersion=" + lastestVersion +
                ", lastSyncTime=" + lastSyncTime +
                '}';
    }
}